package com.fengwk.cv4j.factory;

import com.fengwk.cv4j.compute.Compute;
import com.fengwk.cv4j.view.Var;
import com.fengwk.cv4j.view.VarImpl;
import com.fengwk.cv4j.view.View;
import com.fengwk.cv4j.view.common.AbsView;
import com.fengwk.cv4j.view.common.AddView;
import com.fengwk.cv4j.view.common.AtanView;
import com.fengwk.cv4j.view.common.CeilView;
import com.fengwk.cv4j.view.common.CosView;
import com.fengwk.cv4j.view.common.DivView;
import com.fengwk.cv4j.view.common.EqualsView;
import com.fengwk.cv4j.view.common.ExpView;
import com.fengwk.cv4j.view.common.FloorView;
import com.fengwk.cv4j.view.common.LogView;
import com.fengwk.cv4j.view.common.MaxView;
import com.fengwk.cv4j.view.common.MeanView;
import com.fengwk.cv4j.view.common.MinView;
import com.fengwk.cv4j.view.common.ModView;
import com.fengwk.cv4j.view.common.MulView;
import com.fengwk.cv4j.view.common.NegView;
import com.fengwk.cv4j.view.common.PowView;
import com.fengwk.cv4j.view.common.RoundView;
import com.fengwk.cv4j.view.common.SignView;
import com.fengwk.cv4j.view.common.SinView;
import com.fengwk.cv4j.view.common.SubView;
import com.fengwk.cv4j.view.common.SumView;
import com.fengwk.cv4j.view.common.TanView;

/**
 * 视图工厂的抽象实现</br>
 * 这个类实际上是一个生产模板,以方便子类的继承
 * 
 * @author fengwk
 *
 * @param <T>
 */
public abstract class ViewFactoryImpl<T> implements ViewFactory<T> {

	protected Compute<T> compute;
	
	protected ViewFactoryImpl(Compute<T> compute) {
		this.compute = compute;
	}

	@Override
	public Var<T> of() {
		return new VarImpl<T>(this);
	}
	
	@Override
	public Var<T> of(T t) {
		return new VarImpl<T>(t, this);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> add(View<T> v1, View<T> v2) {
		return new AddView<>(compute, this, v1, v2);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> sub(View<T> v1, View<T> v2) {
		return new SubView<>(compute, this, v1, v2);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> mul(View<T> v1, View<T> v2) {
		return new MulView<>(compute, this, v1, v2);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> div(View<T> v1, View<T> v2) {
		return new DivView<>(compute, this, v1, v2);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> pow(View<T> v1, View<T> v2) {
		return new PowView<>(compute, this, v1, v2);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> exp(View<T> v) {
		return new ExpView<>(compute, this, v);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> log(View<T> v) {
		return new LogView<>(compute, this, v);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View<T> neg(View<T> v) {
		return new NegView<>(compute, this, v);
	}

    @Override
    public View<T> mean(@SuppressWarnings("unchecked") View<T>...vs) {
        return new MeanView<>(compute, this, vs);
    }

    @Override
    public View<T> sum(@SuppressWarnings("unchecked") View<T>...vs) {
        return new SumView<>(compute, this, vs);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> mod(View<T> v1, View<T> v2) {
        return new ModView<>(compute, this, v1, v2);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> abs(View<T> v) {
        return new AbsView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> sign(View<T> v) {
        return new SignView<>(compute, this, v);
    }

    @Override
    public View<T> max(@SuppressWarnings("unchecked") View<T>... vs) {
        return new MaxView<>(compute, this, vs);
    }

    @Override
    public View<T> min(@SuppressWarnings("unchecked") View<T>... vs) {
        return new MinView<>(compute, this, vs);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> cos(View<T> v) {
        return new CosView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> sin(View<T> v) {
        return new SinView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> tan(View<T> v) {
        return new TanView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> atan(View<T> v) {
        return new AtanView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> round(View<T> v) {
        return new RoundView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> floor(View<T> v) {
        return new FloorView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
    @Override
    public View<T> ceil(View<T> v) {
        return new CeilView<>(compute, this, v);
    }

    @SuppressWarnings("unchecked")
	@Override
	public View<T> equals(View<T> v1, View<T> v2) {
		return new EqualsView<>(compute, this, v1, v2);
	}
	
}
